--[[
	围墙类
]]
local Fence = class("Fence")

function Fence:ctor(bound, node)
	self.bound = bound
	self.node = node
	self.fenceSpArray = {}

	--up围墙
	self:fenceGenerator(self.bound, node, function(i)
		SetCollide(i, bound, { Type = "fence" })		
		return cc.exports.Grid2Pos(i, bound)
	end)
	--down围墙
	self:fenceGenerator(self.bound, node, function(i)
		SetCollide(i, -bound, { Type = "fence" })
		return cc.exports.Grid2Pos(i, -bound)
	end)
	--left围墙
	self:fenceGenerator(self.bound, node, function(i)
		SetCollide(bound, i, { Type = "fence" })
		return cc.exports.Grid2Pos(bound, i)
	end)
	--right围墙
	self:fenceGenerator(self.bound, node, function(i)
		SetCollide(-bound, i, { Type = "fence" })
		return cc.exports.Grid2Pos(-bound, i)
	end)
end

function Fence:fenceGenerator(bound, node, callback)
	--i从-bound值开始循环直到bound值结束
	for i = -bound, bound do 
		local sp = cc.Sprite:create("Fence.png")
		local posx, posy = callback(i)
		sp:setPosition(posx, posy)
		node:addChild(sp)
		table.insert(self.fenceSpArray, sp)
	end
end

function Fence:Reset( )
	--亚元变量
	for _, sp in ipairs(self.fenceSpArray) do
		self.node:removeChild(sp)
	end
end

return Fence